<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气案例_监视属性简写</title>
     <script src="../js/vue.js"></script>
</head>
<body>
    
    <div id="root">
        <h1>今天天气非常{{info}}</h1>
        <button @click="changeInfo">切换天气</button>
        
    </div>
    <script>
        const vm = new Vue({
            el:'#root',
            data:{
                ishot:true,
                numbers:{
                    a:1,
                    b:1
                }
            },
            computed:{
                info(){
                    return this.ishot ? '热' : '冷';
                }
            },
            methods: {
                changeInfo(){
                    this.ishot=!this.ishot;
                }
            },
            watch:{
                //正常写法
                /* ishot:{
                    //handler是么时候调用？当ishot发生改变时。
                    handler(newValue,oldValue){
                        console.log('ishot被修改了',oldValue,newValue)
                    }
                }, */
                //简写
                ishot(newValue,oldValue){
                    console.log('ishot被修改了',newValue,oldValue)
                }
                
            }
        });

        //正常写法
        /* vm.$watch('ishot',{
            deep:true,
            handler(newValue,oldValue){
                console.log('ishot被改变了');
            }
        }); */

        //简写
        vm.$watch('ishot',function(newValue,oldValue){
            console.log('ishot被改变了',newValue,oldValue)
        })
    </script>
</body>
</html>